<?php

$permission =   \Velacolib\Utility\Utility::checkPermission($topics->user_id);

$utility = new \Velacolib\Utility\Utility();
$user_info =  \Velacolib\Utility\Utility::GetUserInfo($topics->user_id,'Admin\Model\AdminUserTable');
$userContact = $this->userContact;
?>
<!-- start: Wrapper -->

<div id="wrapper">

    <!-- start: Container -->
    <div class="container">

        <!-- start: detail -->
        <div class="twelve columns">

            <!-- start: Post -->
            <div class="post post-page">
                <div id="page-title-icon"></div>
                <div id="page-title-icon-inner">
                    <i class="ico-google-maps ico-white"></i>
                </div>
                <section id="page-title">
                    <h2><?php echo $topics->title; ?></h2>

                    <h4><a href="/?search_type=<?php echo $topics->topic_type  ?>">[ <?php echo  Velacolib\Utility\Utility::getProductType($topics->topic_type) ?> ]</a> ::<a href="/?search_loc=<?php echo $topics->topic_location; ?>"> <?php echo  Velacolib\Utility\Utility::getLocationArray($topics->topic_location) ?></a> <a href="/?search_cat=<?php echo $topics->cat_id; ?>"><?php $topic_cat =  Velacolib\Utility\Utility::getTopicCat()->getCategories($topics->cat_id); echo $topic_cat->title; ?></a></h4>

                </section>
                <?php count($image)==0 ? $display='height:auto' :$display=''; ?>
                <div class="post-img picture" style="<?php echo $display ?>">
                    <!-- Place somewhere in the <body> of your page -->
                    <div class="flexslider" id="gell">
                        <ul class="slides">
                            <?php foreach($image as $img): ?>
                                <li data-thumb="<?php echo $img->link; ?>">
                                    <img src="<?php echo $img->link; ?>" />
                                </li>
                            <?php endforeach ?>
                            <!-- items mirrored twice, total of 12 -->
                            <?php if(count($image)==0){  ?>
                                <li data-thumb="<?php echo $topics->images; ?>">
                                    <img src="<?php echo $topics->images; ?>" />
                                </li>
                           <?php  } ?>
                        </ul>
                    </div>
                    <?php if($topics->show_price == 1){ ?>
                    <h2 style="color: #ff0000;font-weight: bold">Giá: <?php echo number_format($topics->price ) ?> VNĐ</h2>
                    <?php } else{?>
                    <h2 style="color: #ff0000;font-weight: bold"> Liên Hệ Để Có Giá Tốt </h2>
                   <?php }?>
                </div>
                <?php if($permission){ ?><span class="post-icon standard"><a title="Edit Topic" href="<?php if($permission){ echo $utility->getLinkEdit($topics->id) ;} ?>"><i class="ico-white ico-pen" title="Edit Topic"></i></a></span><?php } ?>
                <div class="post-content">
                    <div class="post-description">
                        <p>
                            <?php echo $topics->full_description; ?>
                        </p>
                    </div>
                    <?php $user =  Velacolib\Utility\Utility::GetUserInfo($topics->user_id,'Admin\Model\AdminUserTable'); ?>

                </div>
            </div>
            <div id="portfolio-wrapper">
            </div>
            <!-- topic image end -->
            <!-- start: Comments -->
            <div class="clear"> </div>
            <?php
            if(count($comment)>=1) {   ?>
                <h4>Comments <span class="comments-amount">*</span></h4>
                <div class="comments-sec">

                    <ol class="commentlist">

                        <?php foreach($comment as $comm): ?>
                            <li>
                                <div class="comments">
                                    <div class="avatar"><img src="http://www.gravatar.com/avatar/00000000000000000000000000000000?d=mm&amp;s=50" alt="" border="0" /> </div>
                                    <div class="comment-des">
                                        <div class="comment-by"><strong><?php $users =  Velacolib\Utility\Utility::GetUserInfo($comm->user_id,'Admin\Model\AdminUserTable'); echo $users->name; ?></strong><span class="reply"><span style="color:#aaa"><span class="date"><?php $comm->create_date ?></span></div>
                                        <p><?php echo $comm->content ?></p>
                                    </div>
                                </div>
                            </li>
                        <?php    endforeach ?>

                    </ol>

                </div>
                <!-- end: Comments -->

            <?php }else{
                echo 'Chưa có bình luận nào cho sản phẩm này';
            } ?>



            <div class="clear"></div>
            <!--paginator -->
            <div class="row-fluid" align="center">
                <?php
                // add at the end of the file after the table
                echo $this->paginationControl(
                // the paginator object
                    $comment,
                    // the scrolling style; see http://zf2.readthedocs.org/en/release-2.1.4/modules/zend.paginator.usage.html#rendering-pages-with-view-scripts
                    'sliding',
                    // the partial to use to render the control
                    array('partial/paginator.phtml', 'Topic'),
                    // the route to link to when a user clicks a control link
                    array(
                        'route' => 'frontendtopic',
                        'child_route' => array(
                            'controller'=>'topic',
                            'action' => 'detail',
                            'id'=>$topics->id
                        )
                    )
                );
                ?>
            </div>
            <!--end paginator -->
            <div class="clear"></div>
            <!-- start: Comment Add -->
            <?php if(\Velacolib\Utility\Utility::isLogin()){ ?>
                <h4>Viết Lời Bình</h4>
                <div class="form-spacer"></div>
                <!-- Form -->
                <div id="contact-form">
                    <form name="comment" method="post" class="require-validate ajax-form-comment" action="<?php echo $this->url ("frontendtopic", array('controller' => 'topic', 'action' => 'comment')) ?>">

                        <!-- <div class="field">
                             <label>Name: <span>*</span></label>
                             <input type="text" name="name" class="text" />
                         </div>

                         <div class="field">
                             <label>Email: <span>*</span></label>
                             <input type="text" class="text" name="email" />
                         </div>
                         -->
                        <div class="field">
                            <label>Lời Bình: <span>*</span></label>
                            <textarea class="text textarea" name="content"  ></textarea>
                        </div>

                        <div class="field">
                            <input type="hidden" name="topic_id" value="<?php echo $topics->id; ?>">
                            <input type="submit" id="send" value="Đăng Bình Luận"/>
                        </div>

                    </form>
                </div>
                <!-- end: Comment Add -->
            <?php
            }
            ?>

        </div>
        <!-- end: detail -->

        <!-- author info -->
        <div class="four columns">
            <ul style="margin-top: 7px;">
                <li class="testimonial">

                    <div class="testimonials">
                        <h3>Người Đăng:</h3>
                        <ul>

                            <li><h4><?php echo $user->name; ?></h4></li>
                            <li><?php echo 'Địa Chỉ: '. $user->address; ?></li>
                            <li><?php echo 'Điện Thoại: '.$user->phone; ?></li>
                            <li><a href="mailto:<?php echo $user->email; ?>"><?php echo 'Email: '.$user->email; ?></a></li>
                            <li><a href="/user/inbox/<?php echo $user->id; ?>">Gởi Tin</a></li>
                            <li>
                                <?php echo $topics->create_date ?>
                            </li>
                            <li>
                                <?php if($permission){ ?><a href="<?php if($permission){ echo $utility->getLinkEdit($topics->id) ;} ?>">Sửa Sản Phẩm</a><?php } ?>
                            </li>
                            <?php
                            if(isset($userContact)){
                                // echo '<pre>';
                                // print_r($userContact);
                                // echo '</pre>';
                                foreach($userContact as $contact){
                                    ?>
                                    <li>
                                        <?php
                                        \Velacolib\Utility\Utility::renderContact($contact); ?>

                                    </li>
                                <?php

                                }
                            }
                            ?>
                        </ul>
                    </div>
                </li>
            </ul>
        </div>
        <!--end author info -->
        <div style="margin: 0 auto" class="loading">Loading...</div>
    </div>
</div>

<script>
    $(window).load(function() {
        $('#gell').flexslider({
            animation: "slide",
            animationLoop: false,
            controlNav: "thumbnails"
        });
    });
</script>